package com.sicau.smarttraceplatform.generator;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @author sxt
 */
public class CodeGenerator {

    public static void main(String[] args) {

        // 代码生成器
        AutoGenerator mpg = new AutoGenerator();

//        全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setOutputDir(System.getProperty("user.dir") + "/src/main/java");
//        globalConfig.setOutputDir("C:\\Users\\sxt\\Desktop\\jd_proj");
        globalConfig.setAuthor("sxt && ttxxi");
        globalConfig.setOpen(true);
        globalConfig.setIdType(IdType.AUTO);
        globalConfig.setServiceName("%sService");

        mpg.setGlobalConfig(globalConfig);

//        数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://47.98.244.28:3306/smart_trace?useUnicode=true&useSSL=false&characterEncoding=utf8&useTimezone=true&serverTimezone=GMT%2B8");
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSourceConfig.setUsername("smart_trace");
        dataSourceConfig.setPassword("smart_trace_173148");

        mpg.setDataSource(dataSourceConfig);

        // 包配置
        PackageConfig pc = new PackageConfig();
//        pc.setModuleName("");
        pc.setParent("com.sicau.smarttraceplatform");
//        pc.setXml("mapper");
        mpg.setPackageInfo(pc);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);


        // TODO: 2020/5/23 数据库表名的补充
//        strategy.setInclude("trace,area,category,collecting_data,good,user,user_area_relation".split(","));


        strategy.setControllerMappingHyphenStyle(true);

        mpg.setStrategy(strategy);
        mpg.execute();
    }

}
